<template>
  <eagle-dialog-page
    :url="url"
    :params="params"
    @initList="_initList"
    @open="open"
    @submit="submit"
    @callbackDialog="callbackDialog"
    @setData="setData"
    v-bind="$attrs"
    v-on="$listeners"
    ref="eagleDialogPage"
    :option="option"
    :selectedValue="selectedValue"
  >
    <eagle-cell v-for="(item, index) in list" :key="index">
      <div class="risk_item_radio">
        <div class="mb-5">
          <div class="mb-10 exam-hd">{{ item.PaperName }}</div>
          <div class="exam-bd">
            <div>包含试题提数：{{ item.TotalQuestions }}</div>
            <div>总分：{{ item.TotalScore || 0 }}分</div>
            <div>及格：{{ item.EvaluationValue || 0 }}分</div>
          </div>
        </div>
        <eagle-checkbox
          v-if="$attrs.isMulti ? $attrs.isMulti : false"
          :name="item.PaperCode"
          shape="round"
        />
        <eagle-radio v-else :name="item.PaperCode" @click="radioClick(item)"></eagle-radio>
      </div>
    </eagle-cell>
  </eagle-dialog-page>
</template>
<script>
export default {
  props: {
    selectedValue: {
      type: String,
      default: () => "",
    },
    tagData: {
      type: [Array, String],
      default: () => [],
    },
  },
  data() {
    return {
      url: "/ExPaper/GetPageData",
      list: [],
      params: [
        {
          Name: "PaperName",
          dataType: "Window",
        },
      ],
      selectedData: [],
      selecteCode: [],
      result: "",
      option: { name: "PaperName", code: "PaperCode" },
      isInit: true,
      multiselectedlist: [],
      orgRowIndex: -1,
      simSelectObject: { PaperCode: "", PaperName: "" },
    };
  },
  computed: {
    multi: {
      get() {
        if (this.$attrs.isMulti) {
          return this.$attrs.isMulti;
        } else {
          return false;
        }
      },
    },
  },
  methods: {
    _initList(list) {
      if (
        this.$attrs.isOpenNew ||
        (this.$attrs.rowIndex && this.$attrs.rowIndex != this.orgRowIndex)
      ) {
        this.orgRowIndex = this.$attrs.rowIndex;
        this.multiselectedlist = [];
      }
      this.list = list;
      this.selecteCode = [];
      var newData = [];
      if (!this.multi) {
        newData = [
          { code: this.selectedValue, PaperCode: this.selectedValue },
        ];
      } else {
        for (var i = 0; i < this.tagData.length; i++) {
          var innerItem = this.tagData[i];
          this.selecteCode.push(innerItem.PaperCode);
          newData.push({
            PaperCode: innerItem.PaperCode,
            PaperName: innerItem.PaperName,
            code: innerItem.PaperCode,
            name: innerItem.PaperName,
          });
        }
      }
      this.$refs.eagleDialogPage.initSeletedData(newData);
      this.multiselectedlist = newData;
    },
    open(list) {
      this.list = list;
    },
    submit() {
      this.$refs.eagleDialogPage.submit();
    },
    setData(data) {
      if (this.multi) {
        this.multiselectedlist = data;
      } else {
        this.simSelectObject = data;
      }
    },
    deleteSelect(code) {
      this.$refs.eagleDialogPage.deleteSelect(code);
    },
    callbackDialog(data) {
      this.$emit("callback", {
        PaperCode: data.PaperCode,
        PaperName: data.PaperName,
      });
    },
    radioClick(item){
      let resultRadio = Object.assign({ code: "", name: "" }, item);
      resultRadio.code = item.PaperCode;
      resultRadio.name = item.PaperName;
      this.$emit("callback", resultRadio);
      this.$emit("update:show", false);
    },
  },
};
</script>
<style lang="less" scoped>
.risk_item_radio {
  width: 100%;
  background-color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.risk {
	height: 100vh;
	background-color: #e8f1f8;

	.info_search {
		padding: 10px;
		border-radius: 5px !important;

		.van-field__control {
			background-color: #ffffff !important;
		}
	}
}

.risk_item_list {
	width: 100%;
	padding: 10px 20px;
	background-color: #fff;
	font-size: 14px;
	border-bottom: 1px solid #e8f1f8;
}

.exam-hd {
	font-size: 15px;
}
.exam-bd {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	color: #666;
	font-size: 12px;
}
</style>